/**
 * 数据服务接口
 */

import axios from "axios";
import utils from "@/utils/utils";

// var root = "http://localhost:8082";
var root = "https://wx.dhfutures.com";

const star = function(callback) {
  var url = root + "/api/score";
  axios.get(url).then(res => {
    callback(res.data.code);
  });
};

// es6 写法
// 用户登录接口
const login = (username, password, callback) => {
  var url = root + "/pub/login";

  let data = new FormData();
  data.append("username", username);
  data.append("password", utils.myMd5(password).toUpperCase());

  axios.post(url, data).then(res => {
    callback(res.data);
  });
};

// 用户退出接口
const loginout = callback => {
  var url = root + "/api/loginout";
  axios.get(url).then(res => {
    callback(res.data);
  });
};

// 获取验证码
const getSns = (phone, callback) => {
  var url = root + "/pub/getSns";

  let data = new FormData();
  data.append("phone", phone);

  axios.post(url, data).then(res => {
    callback(res.data);
  });
};

// 注册
const setRegister = (phone, code, password, callback) => {
  var url = root + "/pub/setRegister";

  let data = new FormData();
  data.append("phone", phone);
  data.append("code", code);
  data.append("password", utils.myMd5(password).toUpperCase());

  axios.post(url, data).then(res => {
    callback(res.data);
  });
};

export { star, login, loginout, getSns, setRegister };
